package com.cwx.mychat.login.authentication;

import com.cwx.mychat.entity.po.UserInfo;
import lombok.Data;
import org.springframework.security.authentication.AbstractAuthenticationToken;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.GrantedAuthority;

import java.util.Collection;

/**
 * 作者： cwx
 * 时间： 2024/10/18 23:48
 * 版本： 1.0
 * 注释：
 */
public class UsernameAuthentication extends AbstractAuthenticationToken {

    private String email;
    private String password;
    private UserInfo currentUser; //认证成功后，后台从数据库获取信息

    public UsernameAuthentication() {

        //现在不用权限直接null
        super(null);
//        super(authorities);
    }

    @Override
    public Object getCredentials() {
        return isAuthenticated() ? null: password;
    }

    @Override
    public Object getPrincipal() {
        return isAuthenticated() ? currentUser: email;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public UserInfo getCurrentUser() {
        return currentUser;
    }

    public void setCurrentUser(UserInfo currentUser) {
        this.currentUser = currentUser;
    }
}
